package com.coolt.client.components;

import com.coolt.client.Labels;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class CooltMenu extends Composite {

	private Labels labelsConstants;
	private VerticalPanel vp = new VerticalPanel();

	public CooltMenu() {

		labelsConstants = GWT.create(Labels.class);

		vp.setSpacing(6);
		vp.setVerticalAlignment(VerticalPanel.ALIGN_TOP);

		Hyperlink linkHome = new Hyperlink(labelsConstants.menuHome(), "home");
		linkHome.setWidth("200");
		linkHome.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {

				CooltMain mainPanel = new CooltMain();
				RootPanel.get("slotMain").clear();
				RootPanel.get("slotMain").add(mainPanel);
			}
		});
		vp.add(itemMenu(linkHome));

		Hyperlink linkCatalogo = new Hyperlink(labelsConstants.menuCatalogue(),
				"catalogue");
		linkCatalogo.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {

				Catalogo panelCatalogo = new Catalogo();
				RootPanel.get("slotMain").clear();
				RootPanel.get("slotMain").add(panelCatalogo);
			}
		});
		vp.add(itemMenu(linkCatalogo));

		Hyperlink linkCoolts = new Hyperlink(labelsConstants.menuCoolts(),
				"coolts");
		linkCoolts.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {

				Usuarios panelUsers = new Usuarios();
				RootPanel.get("slotMain").clear();
				RootPanel.get("slotMain").add(panelUsers);
			}
		});
		vp.add(itemMenu(linkCoolts));

		Hyperlink linkMessages = new Hyperlink(labelsConstants.menuMessages(),
				"messages");
		linkMessages.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {

				Catalogo panelCatalogo = new Catalogo();
				RootPanel.get("slotMain").clear();
				RootPanel.get("slotMain").add(panelCatalogo);
			}
		});
		vp.add(itemMenu(linkMessages));

		Hyperlink linkIndications = new Hyperlink(labelsConstants
				.menuIndications(), "indications");
		linkIndications.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {

				Catalogo panelCatalogo = new Catalogo();
				RootPanel.get("slotMain").clear();
				RootPanel.get("slotMain").add(panelCatalogo);
			}
		});
		vp.add(itemMenu(linkIndications));

		Hyperlink linkCommunities = new Hyperlink(labelsConstants
				.menuCommunities(), "communities");
		linkCommunities.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {

				Communities panelCommunities = new Communities();
				RootPanel.get("slotMain").clear();
				RootPanel.get("slotMain").add(panelCommunities);
			}
		});
		vp.add(itemMenu(linkCommunities));

		initWidget(vp);
		setStyleName("cooltmenu");

	}

	private HorizontalPanel itemMenu(Hyperlink link) {

		HorizontalPanel hp = new HorizontalPanel();
		hp.setSpacing(5);
		hp.add(new Image("img/estrela.gif"));
		hp.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
		link.setStyleName("cooltmenu");
		hp.add(link);

		return hp;
	}
}
